import Vue from 'vue'
import Vuex from 'vuex'
import mutations from "./mutations";
import actions from "./actions";
import getters from "./getters";

import createPersistedState from "vuex-persistedstate"

Vue.use(Vuex)

const state = {
  cartList: [],
  common: {
    BCcontextPathSrc: ''
  }
}

export default new Vuex.Store({
  state,
  mutations,
  getters,
  actions,
  modules: {},
  //持久化插件 原理就是放到緩存
  plugins: [createPersistedState({
    // storage: window.sessionStorage,  // 把vuex的数据存储到sessionStorage
    reducer(state) {        
      
      return {          
          // 只存储state中的userData          
          userData: state.cartList        
      }      
  }  
  })]
})
